/**
 * 
 */
package com.obradovicnjegovan.webprodavnica.components;

import org.apache.shiro.subject.Subject;
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.tynamo.security.services.SecurityService;

/**
 * @author njegovan
 * 
 */
@Import(stylesheet = { "context:layout/admin/css/bootstrap.min.css",
		"context:layout/admin/css/dashboard.css",
		"context:layout/admin/css/admin.css" }, library = {
		"context:layout/admin/js/vendor/bootstrap.min.js",
		"context:layout/admin/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js",
		"context:layout/admin/js/main.js" })
public class AdminLayout {
	/**
	 * The page title, for the <title> element and the <h1>element.
	 */
	@Property
	@Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
	private String title;

	@Property
	private String pageName;

	@Inject
	private ComponentResources resources;

	public String getClassForPageName() {
		return resources.getPageName().equalsIgnoreCase(pageName) ? "current_page_item"
				: null;
	}

	public String[] getPageNames() {
		return new String[] { "Admin/Index", "Admin/NoviProizvod", "Admin/Proizvodi", "Admin/NovaKategorija", "Admin/Kategorije" };
	}

	public String displayFormatedPageNames(String pageName) {
		String pn;
		switch (pageName) {
		case "Admin/Index":
			pn = "Narudzbenice";
			break;
		case "Admin/NoviProizvod":
			pn = "Novi Proizvod";
			break;
		case "Admin/Proizvodi":
			pn = "Svi Proizvodi";
			break;
		case "Admin/NovaKategorija":
			pn = "Nova Kategorija";
			break;
		case "Admin/Kategorije":
			pn = "Kategorije";
			break;
			
		default:
			pn = pageName;
			break;
		}
		return pn;
	}
	
    @Inject
    private SecurityService securityService;
    
    void onLogout(){
            Subject currentUser = securityService.getSubject();
            currentUser.logout();
    }
}